<?php include load_tpl('header');?>
<p id="breadcrumbs">
    <a href="/">首页</a> <b>»</b> 
    <span>添加产品图片</span>
</p>
<?php if($messages){
	echo '<div class="warning"><ol class="error">';
	foreach($messages as $msg){
		echo '<li>'.$msg.'</li>';
	}
	echo '</ol></div>';
}
?>
<form action="" method="post" id="addform"  enctype="multipart/form-data">
<label>选择产品：</label>
<select name="product_id" style="width:400px;">
<?php echo $product_select;?>
</select>
<table class="list" id="images">
  <thead>
	<tr style="background-color: rgb(244, 244, 248);">
	  <td class="left">上传产品图片:<br><span class="help">Click on the image to change it.</span></td>
	  <td></td>
	</tr>
  </thead>
  <?php if($img_arr){
		foreach($img_arr as $k=>$img){
  ?>
<tbody id="image_row<?php echo $k;?>"><tr><td class="left"><input type="file" id="image2" value="" name="product_image[]"><img src="product_images/<?php echo $img['thumbnail']?>" alt="" class="image"><input type="hidden" name="imageid[]" value="<?php echo $img['product_image_id'];?>"></td><td class="left"><a class="button" onclick="$('#image_row<?php echo $k;?>').remove();"><span>移除图片</span></a></td></tr></tbody>
  <?php
		} 
  }else{
  ?>
 <tbody id="image_row2"><tr><td class="left"><input type="file" id="image2" value="" name="product_image[]"></td><td class="left"><a class="button" onclick="$('#image_row2').remove();"><span>移除图片</span></a></td></tr></tbody>
 <tbody id="image_row3"><tr><td class="left"><input type="file" id="image3" value="" name="product_image[]"></td><td class="left"><a class="button" onclick="$('#image_row3').remove();"><span>移除图片</span></a></td></tr></tbody>
 <tbody id="image_row4"><tr><td class="left"><input type="file" id="image4" value="" name="product_image[]"></td><td class="left"><a class="button" onclick="$('#image_row4').remove();"><span>移除图片</span></a></td></tr></tbody>
 <tbody id="image_row5"><tr><td class="left"><input type="file" id="image5" value="" name="product_image[]"></td><td class="left"><a class="button" onclick="$('#image_row5').remove();"><span>移除图片</span></a></td></tr></tbody>
 <tbody id="image_row6"><tr><td class="left"><input type="file" id="image6" value="" name="product_image[]"></td><td class="left"><a class="button" onclick="$('#image_row6').remove();"><span>移除图片</span></a></td></tr></tbody>
  <?php } ?>
  <input type="hidden" name="oldimgids" value="<?php if($img_ids) echo $img_ids;?>">
  <tfoot>
	<tr>
	  <td><a class="button" onclick="$('#addform').submit();"><span>上传所有图片</span></a></td>
	  <td class="left"><a class="button" onclick="addImage();"><span>增加图片</span></a></td>
	</tr>
  </tfoot>
</table>
</form>
<?php include load_tpl('footer');?>

<script type="text/javascript">
<!--
<?php if($img_arr){?>
var image_row = <?php echo $k; ?>;
<?php }else{ ?>
var image_row = 7;
<?php } ?>
function addImage() {
html = '<tbody id="image_row' + image_row + '">';
html += '<tr>';
html += '<td class="left"><input type="file" name="product_image[]" value="" id="image' + image_row + '" /></td>';
html += '<td class="left"><a onclick="$(\'#image_row' + image_row + '\').remove();" class="button"><span>移除图片</span></a></td>';
html += '</tr>';
html += '</tbody>';
$('#images tfoot').before(html);
image_row++;
}
//-->
</script> 